﻿// -----------------------------------------------------------------------
// <copyright file="Path.cs" company="Company">
// Company 2011
// </copyright>
// -----------------------------------------------------------------------

using System.Runtime.InteropServices;
using Company.IO.Interfaces;

namespace Company.System.IO
{
    /// <summary>
    /// Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner.
    /// </summary>
    [Guid("8ee22d6f-38f9-476d-a063-e957119ca23a")]
    public class Path : IPath
    {
        #region IPath Members

        /// <summary>
        /// Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.
        /// </summary>
        char IPath.DirectorySeparatorChar
        {
            get { return global::System.IO.Path.DirectorySeparatorChar; }
        }

        /// <summary>
        /// Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.
        /// </summary>
        char IPath.AltDirectorySeparatorChar
        {
            get { return global::System.IO.Path.AltDirectorySeparatorChar; }
        }

        /// <summary>
        /// Provides a platform-specific volume separator character.
        /// </summary>
        char IPath.VolumeSeparatorChar
        {
            get { return global::System.IO.Path.VolumeSeparatorChar; }
        }

        /// <summary>
        /// Provides a platform-specific array of characters that cannot be specified in path string arguments passed to members of the Path class.
        /// </summary>
        char[] IPath.InvalidPathChars
        {
            get { return global::System.IO.Path.GetInvalidPathChars(); }
        }

        /// <summary>
        /// A platform-specific separator character used to separate path strings in environment variables.
        /// </summary>
        char IPath.PathSeparator
        {
            get { return global::System.IO.Path.PathSeparator; }
        }

        /// <summary>
        /// Changes the extension of a path string.
        /// </summary>
        /// <param name="path">The path information to modify. The path cannot contain any of the characters defined in GetInvalidPathChars.</param>
        /// <param name="extension">The new extension (with or without a leading period). Specify a null reference (Nothing in Visual Basic) to remove an existing extension from path.</param>
        /// <returns>
        /// The modified path information.
        /// On Windows-based desktop platforms, if path is a null reference (Nothing in Visual Basic) or an empty string (""),
        /// the path information is returned unmodified.
        /// If extension is a null reference (Nothing in Visual Basic), the returned string contains the specified path with its extension removed.
        /// If path has no extension, and extension is not a null reference (Nothing in Visual Basic),
        /// the returned path string contains extension appended to the end of path.
        /// </returns>
        string IPath.ChangeExtension(string path, string extension)
        {
            return global::System.IO.Path.ChangeExtension(path, extension);
        }

        /// <summary>
        /// Returns the directory information for the specified path string.
        /// </summary>
        /// <param name="path">The path of a file or directory.</param>
        /// <returns>
        /// Directory information for path, or a null reference (Nothing in Visual Basic) if path denotes a root directory or is null.
        /// Returns String.Empty if path does not contain directory information.
        /// </returns>
        string IPath.GetDirectoryName(string path)
        {
            return global::System.IO.Path.GetDirectoryName(path);
        }

        /// <summary>
        /// Gets an array containing the characters that are not allowed in path names.
        /// </summary>
        /// <returns>
        /// An array containing the characters that are not allowed in path names.
        /// </returns>
        char[] IPath.GetInvalidPathChars()
        {
            return global::System.IO.Path.GetInvalidPathChars();
        }

        /// <summary>
        /// Gets an array containing the characters that are not allowed in file names.
        /// </summary>
        /// <returns>
        /// An array containing the characters that are not allowed in file names.
        /// </returns>
        char[] IPath.GetInvalidFileNameChars()
        {
            return global::System.IO.Path.GetInvalidFileNameChars();
        }

        /// <summary>
        /// Returns the extension of the specified path string.
        /// </summary>
        /// <param name="path">The path string from which to get the extension.</param>
        /// <returns>
        /// The extension of the specified path (including the period "."), or a null reference (Nothing in Visual Basic), or String.Empty.
        /// If path is a null reference (Nothing in Visual Basic), GetExtension returns a null reference (Nothing in Visual Basic).
        /// If path does not have extension information, GetExtension returns String.Empty.
        /// </returns>
        string IPath.GetExtension(string path)
        {
            return global::System.IO.Path.GetExtension(path);
        }

        /// <summary>
        /// Returns the absolute path for the specified path string.
        /// </summary>
        /// <param name="path">The file or directory for which to obtain absolute path information.</param>
        /// <returns>
        /// The fully qualified location of path, such as "C:\MyFile.txt".
        /// </returns>
        string IPath.GetFullPath(string path)
        {
            return global::System.IO.Path.GetFullPath(path);
        }

        /// <summary>
        /// Returns the file name and extension of the specified path string.
        /// </summary>
        /// <param name="path">The path string from which to obtain the file name and extension.</param>
        /// <returns>
        /// The characters after the last directory character in path.
        /// If the last character of path is a directory or volume separator character, this method returns String.Empty.
        /// If path is a null reference (Nothing in Visual Basic), this method returns a null reference (Nothing in Visual Basic).
        /// </returns>
        string IPath.GetFileName(string path)
        {
            return global::System.IO.Path.GetFileName(path);
        }

        /// <summary>
        /// Returns the file name of the specified path string without the extension.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <returns>
        /// The string returned by GetFileName, minus the last period (.) and all characters following it.
        /// </returns>
        string IPath.GetFileNameWithoutExtension(string path)
        {
            return global::System.IO.Path.GetFileNameWithoutExtension(path);
        }

        /// <summary>
        /// Gets the root directory information of the specified path.
        /// </summary>
        /// <param name="path">The path from which to obtain root directory information.</param>
        /// <returns>
        /// The root directory of path, such as "C:\",
        /// or a null reference (Nothing in Visual Basic) if path is a null reference (Nothing in Visual Basic),
        /// or an empty string if path does not contain root directory information.
        /// </returns>
        string IPath.GetPathRoot(string path)
        {
            return global::System.IO.Path.GetPathRoot(path);
        }

        /// <summary>
        /// Returns the path of the current user's temporary folder.
        /// </summary>
        /// <returns>
        /// The path to the temporary folder, ending with a backslash.
        /// </returns>
        string IPath.GetTempPath()
        {
            return global::System.IO.Path.GetTempPath();
        }

        /// <summary>
        /// Returns a random folder name or file name.
        /// </summary>
        /// <returns>
        /// A random folder name or file name.
        /// </returns>
        string IPath.GetRandomFileName()
        {
            return global::System.IO.Path.GetRandomFileName();
        }

        /// <summary>
        /// Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
        /// </summary>
        /// <returns>
        /// The full path of the temporary file.
        /// </returns>
        string IPath.GetTempFileName()
        {
            return global::System.IO.Path.GetTempFileName();
        }

        /// <summary>
        /// Determines whether a path includes a file name extension.
        /// </summary>
        /// <param name="path">The path to search for an extension.</param>
        /// <returns>
        /// true if the characters that follow the last directory separator (\\ or /) or volume separator (:) in the path
        /// include a period (.) followed by one or more characters; otherwise, false.
        /// </returns>
        bool IPath.HasExtension(string path)
        {
            return global::System.IO.Path.HasExtension(path);
        }

        /// <summary>
        /// Gets a value indicating whether the specified path string contains a root.
        /// </summary>
        /// <param name="path">The path to test.</param>
        /// <returns>
        /// true if path contains a root; otherwise, false.
        /// </returns>
        bool IPath.IsPathRooted(string path)
        {
            return global::System.IO.Path.IsPathRooted(path);
        }

        /// <summary>
        /// Combines two strings into a path.
        /// </summary>
        /// <param name="path1">The first path to combine.</param>
        /// <param name="path2">The second path to combine.</param>
        /// <returns>
        /// The combined paths. If one of the specified paths is a zero-length string, this method returns the other path.
        /// If path2 contains an absolute path, this method returns path2.
        /// </returns>
        string IPath.Combine(string path1, string path2)
        {
            return global::System.IO.Path.Combine(path1, path2);
        }

        /// <summary>
        /// Combines three strings into a path.
        /// </summary>
        /// <param name="path1">The first path to combine.</param>
        /// <param name="path2">The second path to combine.</param>
        /// <param name="path3">The third path to combine.</param>
        /// <returns>
        /// The combined paths.
        /// </returns>
        string IPath.Combine(string path1, string path2, string path3)
        {
            return global::System.IO.Path.Combine(path1, path2, path3);
        }

        /// <summary>
        /// Combines four strings into a path.
        /// </summary>
        /// <param name="path1">The first path to combine.</param>
        /// <param name="path2">The second path to combine.</param>
        /// <param name="path3">The third path to combine.</param>
        /// <param name="path4">The fourth path to combine.</param>
        /// <returns>the combined string</returns>
        string IPath.Combine(string path1, string path2, string path3, string path4)
        {
            return global::System.IO.Path.Combine(path1, path2, path3, path4);
        }

        /// <summary>
        /// Combines an array of strings into a path.
        /// </summary>
        /// <param name="paths">An array of parts of the path.</param>
        /// <returns>
        /// The combined paths.
        /// </returns>
        string IPath.Combine(params string[] paths)
        {
            return global::System.IO.Path.Combine(paths);
        }

        #endregion
    }
}